﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;

namespace SchoolManagementSystem.Details
{
    public partial class Product_AttributeUC : DetailUC
    {
        public Product_AttributeUC()
        {
            InitializeComponent();
            this.Code = "ProductAttribute";
            this.ObjectName = "Thuộc tính hàng hóa";
            this.Type = new Product_Attribute();

            comboboxUC_Attribute.Model = RegisterService.RegisterServices.AttributeService;
            comboboxUC_Attribute.Uc = new AttributeUC();
            comboboxUC_Attribute.ColumnMain = "Name";
            comboboxUC_Attribute.ColumnDisplay = "Code,Name";
            

        }
        String Product_AttributeID = "1=1";
        protected override long DetailDisplay()
        {
            Product_Attribute data = new Product_Attribute();
            if (ID > 0)
            {
                data = (Product_Attribute)RegisterService.RegisterServices.Product_AttributeService.GetByID(ID);
                Product_AttributeID = data.ID.ToString();
            }
            else
            {
                data.Value = "";
            }
            commandBarUC1.cmdnew.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            comboboxUC_Attribute.ID = data.AttributeID;
            txtAttrValue.Text = data.Value;
            ckactive.Checked = data.Active;
            return ID;
        }

        protected override long Save()
        {
            Product_Attribute data = new Product_Attribute();
            //if (ID > 0)
            //{
            //    data = (Product_Attribute)RegisterService.RegisterServices.Product_AttributeService.GetByID(data.ID);
            //}
            if (ID > 0)
            {
                //data.ID = ID;
                data = (Product_Attribute)RegisterService.RegisterServices.Product_AttributeService.GetByID(ID);
            }
            long pID = long.Parse(SearchString.Replace("'", "").Replace("ProductID=", "").Trim());
            data.ProductID = pID;
            data.AttributeID = comboboxUC_Attribute.ID;
            data.Value = txtAttrValue.Text;
            data.Active = ckactive.Checked;
            ID = RegisterService.RegisterServices.Product_AttributeService.Save(data,ref ErrorMess);
            return ID;

        }
        public override bool Delete(long SelectedID)
        {

            return RegisterService.RegisterServices.Product_AttributeService.Delete(RegisterService.RegisterServices.Product_AttributeService.GetByID(SelectedID));

        }
        private void Product_AttributeUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl1.Controls);
        }
    }
}
